<template>
    <Topbar></Topbar>

    <van-cell-group inset>
        <van-cell>
            <template #title>
                <div class="cell">
                    <van-image width="100" height="100" :src="`/api${user.avatar}`"/>

                    <div class="user-info">
                        <h2>
                          {{ user.name }}</h2>
                        <p><span>vv:</span>{{ user.account }}</p>
                    </div>
                </div>

            </template>
        </van-cell>
        <van-cell title="性别" :value="user.sex==1?'男':'女'" />
        <!--    <van-cell title="个性化签名" value="撒娇的" label="描述信息">-->
        <!--    个性签名-->
        <van-cell>
            <template #title>
                <div class="cell">
                    <div class="user-sign">
                        <h3>个性签名：</h3>
                        <p>{{ user.individuality }}</p>
                    </div>
                </div>

            </template>
        </van-cell>
    </van-cell-group>
  <!--编辑信息-->
    <van-button type="danger" @click="delFriend" block class="btn-save">删除好友 </van-button>
</template>

<script setup lang="ts">

import Topbar from "../../components/Topbar.vue";
import {
  useFriendStore
} from "../../store/friend";
import {
  useRoute
} from "vue-router";
import {
  onMounted,
  ref
} from "vue";
import {
  UserResponseData
} from "../../type/friend";

// 实例化路由
const route = useRoute()
//接收好友id     不能直接接收要将其转为Number属性
const friendId = Number(route.query.id)


//实例化好友请求列表
const friendStore = useFriendStore();

// @ts-ignore
const user = ref<UserResponseData>({})
onMounted(async ()=>{
  //调用请求                              传递好友id
  const result = await friendStore.getFindUserById(friendId)
  //接收服务器返回来的好友信息
  user.value = result.user
})

//点击删除好友调用删除好友请求
const delFriend = () => {
  friendStore.delFriend(friendId)
}

</script>

<style scoped lang="less">
.cell{
  display: flex;
  align-items: center;
  .user-info{
    padding-left: 2rem;
    //账号样式
    p{
      margin-top: 5px;
      color: #8d8d8d;
      font-size: 1rem;

      span{
        margin-right: 5px;
      }
    }

  }
  .user-sign{
    p{
      margin-top: 5px;
      //color: #8d8d8d;
      font-size: 1rem;

      span{
        margin-right: 5px;
      }
    }
  }
}
.btn-save{
  position: fixed;
  bottom: 0;
}
</style>